<!DOCTYPE html>
<html  lang="zh">
<head>
    <!-- hexo-inject:begin --><!-- hexo-inject:end --><meta charset="utf-8" />

<meta name="generator" content="Hexo 3.9.0" />

<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />

<title>xlua学习 - 游戏人生</title>


    <meta name="description" content="学习状态同步的概念">
<meta name="keywords" content="学习">
<meta property="og:type" content="article">
<meta property="og:title" content="xlua学习">
<meta property="og:url" content="http://cloundgame.gitee.io/mystudy/2019/08/22/xlua学习/index.html">
<meta property="og:site_name" content="游戏人生">
<meta property="og:description" content="学习状态同步的概念">
<meta property="og:locale" content="zh-CN">
<meta property="og:image" content="http://cloundgame.gitee.io/mystudy/images/og_image.png">
<meta property="og:updated_time" content="2019-08-21T20:59:43.091Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="xlua学习">
<meta name="twitter:description" content="学习状态同步的概念">
<meta name="twitter:image" content="http://cloundgame.gitee.io/mystudy/images/og_image.png">







<link rel="icon" href="/mystudy/images/favicon.svg">


<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@0.7.2/css/bulma.css">
<link rel="stylesheet" href="https://cdn.bootcdn.net/ajax/libs/font-awesome/5.9.0/css/all.min.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Ubuntu:400,600|Source+Code+Pro">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/highlight.js@9.12.0/styles/atom-one-dark.css">


    
    
    
    <style>body>.footer,body>.navbar,body>.section{opacity:0}</style>
    

    
    
    
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/lightgallery@1.6.8/dist/css/lightgallery.min.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/justifiedGallery@3.7.0/dist/css/justifiedGallery.min.css">
    

    
    

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/outdatedbrowser@1.1.5/outdatedbrowser/outdatedbrowser.min.css">


    
    
    
    

<link rel="stylesheet" href="/mystudy/css/back-to-top.css">


    
    

    
    
    
    

    
    
<link rel="stylesheet" href="/mystudy/css/progressbar.css">
<script src="https://cdn.jsdelivr.net/npm/pace-js@1.0.2/pace.min.js"></script>

    
    
    
        <script async="" src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
    

    


<link rel="stylesheet" href="/mystudy/css/style.css"><!-- hexo-inject:begin --><!-- hexo-inject:end -->
</head>
<body class="is-3-column">
    <!-- hexo-inject:begin --><!-- hexo-inject:end --><nav class="navbar navbar-main">
    <div class="container">
        <div class="navbar-brand is-flex-center">
            <a class="navbar-item navbar-logo" href="/mystudy/">
            
                <img src="/mystudy/images/logo.svg" alt="xlua学习" height="28">
            
            </a>
        </div>
        <div class="navbar-menu">
            
            <div class="navbar-start">
                
                <a class="navbar-item"
                href="/mystudy/">主页</a>
                
                <a class="navbar-item"
                href="/mystudy/archives">日志</a>
                
                <a class="navbar-item"
                href="/mystudy/categories">分类</a>
                
                <a class="navbar-item"
                href="/mystudy/">关于</a>
                
            </div>
            
            <div class="navbar-end">
                
                    
                    
                    <a class="navbar-item" target="_blank" title="Download on GitHub" href="https://github.com/koliy/koliy.github.io">
                        
                        <i class="fab fa-github"></i>
                        
                    </a>
                    
                
                
                <a class="navbar-item is-hidden-tablet catalogue" title="目录" href="javascript:;">
                    <i class="fas fa-list-ul"></i>
                </a>
                
                
                <a class="navbar-item search" title="搜索" href="javascript:;">
                    <i class="fas fa-search"></i>
                </a>
                
            </div>
        </div>
    </div>
</nav>
    
    <section class="section">
        <div class="container">
            <div class="columns">
                <div class="column is-8-tablet is-8-desktop is-6-widescreen has-order-2 column-main"><div class="card">
    
    <div class="card-content article ">
        
        <div class="level article-meta is-size-7 is-uppercase is-mobile is-overflow-x-auto">
            <div class="level-left">
                <time class="level-item has-text-grey" datetime="2019-08-21T20:16:47.000Z">2019-08-22</time>
                
                <div class="level-item">
                <a class="has-link-grey -link" href="/mystudy/categories/xlua/">xlua</a>
                </div>
                
                
                <span class="level-item has-text-grey">
                    
                    
                    12 分钟 读完 (大约 1778 个字)
                </span>
                
                
                <span class="level-item has-text-grey" id="busuanzi_container_page_pv">
                    <i class="far fa-eye"></i>
                    <span id="busuanzi_value_page_pv">0</span>次访问
                </span>
                
            </div>
        </div>
        
        <h1 class="title is-size-3 is-size-4-mobile has-text-weight-normal">
            
                xlua学习
            
        </h1>
        <div class="content">
            <h2 id="LuaEnv类"><a href="#LuaEnv类" class="headerlink" title="LuaEnv类"></a>LuaEnv类</h2><h3 id="Tick"><a href="#Tick" class="headerlink" title="Tick"></a>Tick</h3><p>清除Lua的未手动释放的LuaBase对象（如：LuaTable、LuaFunction），以及其它一些事情。</p>
<p>需要定期调用，比如每秒在MonoBehaviour的Update中调用。</p>
<a id="more"></a>
<hr>
<h3 id="Dispose"><a href="#Dispose" class="headerlink" title="Dispose"></a>Dispose</h3><p>void Dispose()<br>Dispose该LuaEnv。<br>使用建议</p>
<p>全局只创建一个LuaEnv实例，并在Update中调用GC方法，完全不需要时调用Dispose</p>
<hr>
<h3 id="Global"><a href="#Global" class="headerlink" title="Global"></a>Global</h3><p>LuaTable Global<br>代表lua全局环境的LuaTable</p>
<p>luaenv.Global.xxx</p>
<hr>
<h3 id="DoString"><a href="#DoString" class="headerlink" title="DoString"></a>DoString</h3><p>object[] DoString(string chunk, string chunkName = “chuck”, LuaTable env = null)<br>执行一个代码块<br>参数</p>
<figure class="highlight lua hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">chunk - Lua代码的字符串</span><br><span class="line">chunkName - 发生<span class="hljs-built_in">error</span>时的<span class="hljs-built_in">debug</span>显示信息中使用，指明某某代码块的某行错误</span><br><span class="line">env - 这个代码块的环境变量</span><br></pre></td></tr></table></figure>

<p>返回值<br>代码块里return语句的返回值</p>
<figure class="highlight lua hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">LuaEnv luaenv = new LuaEnv();</span><br><span class="line">object[] ret = luaenv.DoString(@<span class="hljs-string">"print('helloworld')\r\n return 1,'heLLo'"</span>);</span><br><span class="line">luaenv.Dispose();</span><br></pre></td></tr></table></figure>

<hr>
<h3 id="加载lua文件"><a href="#加载lua文件" class="headerlink" title="加载lua文件"></a>加载lua文件</h3><ol>
<li>lua文件必须以xxx.lua.txt保存，放入Resources目录下。不能放入RES的子目录中。如果想把lua放入任意目录下，需要自定义loader。</li>
<li>luaenv.DoString(@”require ‘testlua’”);</li>
<li>require在加载时会使用默认的Loader函数去加载文件，此函数可以自定义。</li>
</ol>
<hr>
<h3 id="AddLoader"><a href="#AddLoader" class="headerlink" title="AddLoader"></a>AddLoader</h3><p>void AddLoader(CustomLoader loader)<br>添加一个自定义loader。当一个文件被require时，这个loader会被回调，其参数是调用require所使用的参数。如果该loader找到文件，可以将其读进内存，返回一个byte数组。如果需要支持调试的话，filepath要设置成IDE能找到的路径（相对或者绝对都可以）。</p>
<p><strong>参数</strong></p>
<figure class="highlight lua hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">loader - 一个包括了加载函数的委托，其类型为delegate <span class="hljs-built_in">byte</span>[] CustomLoader(ref <span class="hljs-built_in">string</span> filepath)。</span><br></pre></td></tr></table></figure>

<p><strong>列子</strong></p>
<figure class="highlight lua hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">luaenv.AddLoader(LuaLoader);</span><br><span class="line">luaenv.DoString(@<span class="hljs-string">"require  'testlua'"</span>);</span><br><span class="line">		</span><br><span class="line">private <span class="hljs-built_in">byte</span>[] LuaLoader(ref <span class="hljs-built_in">string</span> filepath)</span><br><span class="line">&#123;</span><br><span class="line">    TextAsset lua = Resources.Load(<span class="hljs-string">"lua/"</span> + filepath + <span class="hljs-string">".lua"</span>) as TextAsset;</span><br><span class="line">    <span class="hljs-keyword">return</span> lua.bytes;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p><em>建议的加载Lua脚本方式是：整个程序就一个DoString(“require ‘main’”)，然后在main.lua加载其它脚本（类似lua脚本的命令行执行：lua main.lua）</em></p>
<h2 id="LuaTable类"><a href="#LuaTable类" class="headerlink" title="LuaTable类"></a>LuaTable类</h2><h3 id="Get"><a href="#Get" class="headerlink" title="Get"></a>Get</h3><p>T Get<t>(string key)<br>获取在key下，类型为T的value，如果不存在或者类型不匹配，返回null。</t></p>
<figure class="highlight lua hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">number = <span class="hljs-number">1</span></span><br><span class="line">Debug.Log(<span class="hljs-string">"number = "</span> + luaenv.Global.Get&lt;int&gt;(<span class="hljs-string">"number"</span>));</span><br></pre></td></tr></table></figure>

<h4 id="获取一个table表"><a href="#获取一个table表" class="headerlink" title="获取一个table表"></a>获取一个table表</h4><p>lua</p>
<figure class="highlight lua hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">Table&#123;</span><br><span class="line">	f1=<span class="hljs-number">1</span>, </span><br><span class="line">	f2=<span class="hljs-number">2</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p><strong>则需要将Table映射为C#中相对应的数据结构，可选的方式有：class，interface，Dictionary，List和LuaTable</strong></p>
<h4 id="1-以class做映射"><a href="#1-以class做映射" class="headerlink" title="1.以class做映射:"></a>1.以class做映射:</h4><p>需要在C#中定义一个相对应的类即可，注意变量名称要和Table中的名称相同，xLua会依次在table中寻找是否有与class中变量名相同的key值，如果有则将其value值复制到对应的变量上，如果在Table的Key值中找不到与定义的class的变量，则变量会被赋于对应类型的初值</p>
<figure class="highlight csharp hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="hljs-keyword">class</span> <span class="hljs-title">Table</span></span><br><span class="line">&#123;</span><br><span class="line">    <span class="hljs-keyword">public</span> <span class="hljs-keyword">int</span> f1;</span><br><span class="line">    <span class="hljs-keyword">public</span> <span class="hljs-keyword">int</span> f2;</span><br><span class="line">&#125;</span><br><span class="line">Table table = luaenv.Global.Get&lt;Table&gt;(<span class="hljs-string">"table"</span>);</span><br><span class="line">Debug.Log(<span class="hljs-string">"table.f1 = "</span> + table.f1);</span><br></pre></td></tr></table></figure>

<h4 id="2-Dictionary做映射"><a href="#2-Dictionary做映射" class="headerlink" title="2.Dictionary做映射"></a>2.Dictionary做映射</h4><p>速度比较慢</p>
<figure class="highlight csharp hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">Dictionary&lt;<span class="hljs-keyword">string</span>, <span class="hljs-keyword">int</span>&gt; dict = luaenv.Global.Get&lt;Dictionary&lt;<span class="hljs-keyword">string</span>, <span class="hljs-keyword">int</span>&gt;&gt;(<span class="hljs-string">"Table"</span>);</span><br><span class="line">Debug.Log(<span class="hljs-string">"dict1 ="</span> + dict[<span class="hljs-string">"f1"</span>]);</span><br></pre></td></tr></table></figure>

<h4 id="3-以LuaTable映射"><a href="#3-以LuaTable映射" class="headerlink" title="3.以LuaTable映射"></a>3.以LuaTable映射</h4><p>速度比较慢</p>
<figure class="highlight csharp hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="hljs-comment">//返回以个table表</span></span><br><span class="line">LuaTable tb = luaenv.Global.Get&lt;LuaTable&gt;(<span class="hljs-string">"tb"</span>);</span><br><span class="line">Debug.Log(<span class="hljs-string">"tb ="</span> + tb.Get&lt;<span class="hljs-keyword">int</span>&gt;(<span class="hljs-string">"f1"</span>));</span><br></pre></td></tr></table></figure>

<h4 id="4-以List做映射"><a href="#4-以List做映射" class="headerlink" title="4.以List做映射"></a>4.以List做映射</h4><p>lua:</p>
<figure class="highlight lua hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">list=&#123;</span><br><span class="line">	<span class="hljs-number">1</span>,</span><br><span class="line">	<span class="hljs-number">2</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>c#</p>
<figure class="highlight csharp hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">List&lt;<span class="hljs-keyword">int</span>&gt; list = luaenv.Global.Get&lt;List&lt;<span class="hljs-keyword">int</span>&gt;&gt;(<span class="hljs-string">"list"</span>);</span><br><span class="line">Debug.Log(<span class="hljs-string">"list ="</span> + list[<span class="hljs-number">0</span>]);</span><br></pre></td></tr></table></figure>

<h4 id="5-以interface做映射"><a href="#5-以interface做映射" class="headerlink" title="5.以interface做映射"></a>5.以interface做映射</h4><p>对于table中有函数的，需要interface映射,这种方式读取table时需要生成代码，必须要给接口加上[CSharpCallLua]<br><strong>点击xlua/generate code生成代码。</strong><br>lua:</p>
<figure class="highlight lua hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">itable=&#123;</span><br><span class="line">	f1=<span class="hljs-number">1</span>,</span><br><span class="line">	add = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(self,num1,num2)</span></span></span><br><span class="line">		<span class="hljs-keyword">return</span> num1 + num2;</span><br><span class="line">	<span class="hljs-keyword">end</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>c#</p>
<figure class="highlight csharp hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">[<span class="hljs-meta">CSharpCallLua</span>]</span><br><span class="line"><span class="hljs-keyword">public</span> <span class="hljs-keyword">interface</span> <span class="hljs-title">ITable</span></span><br><span class="line">&#123;</span><br><span class="line">    <span class="hljs-keyword">int</span> f1 &#123; <span class="hljs-keyword">get</span>; <span class="hljs-keyword">set</span>; &#125;</span><br><span class="line">    <span class="hljs-function"><span class="hljs-keyword">int</span> <span class="hljs-title">add</span>(<span class="hljs-params"><span class="hljs-keyword">int</span> num1, <span class="hljs-keyword">int</span> num2</span>)</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">ITable itable = luaenv.Global.Get&lt;ITable&gt;(<span class="hljs-string">"itable"</span>);</span><br><span class="line">Debug.Log(<span class="hljs-string">"itable ="</span> + itable.f1);</span><br><span class="line">Debug.Log(<span class="hljs-string">"itable add="</span> + itable.<span class="hljs-keyword">add</span>(<span class="hljs-number">1</span>,<span class="hljs-number">2</span>));</span><br></pre></td></tr></table></figure>

<h4 id="6-获取全局函数"><a href="#6-获取全局函数" class="headerlink" title="6. 获取全局函数"></a>6. 获取全局函数</h4><p>一般来说，全局函数的映射方式有两种，一种是使用delegate(要生成代码，性能好)，<br>另一种是使用LuaFunction（不用生成代码，用该类访问Lua函数会有boxing，unboxing的开销，性能较差）。</p>
<figure class="highlight csharp hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="hljs-function">function <span class="hljs-title">action0</span>(<span class="hljs-params"></span>)</span></span><br><span class="line"><span class="hljs-function">	<span class="hljs-title">print</span>(<span class="hljs-params"><span class="hljs-string">"action0 call"</span></span>)</span></span><br><span class="line"><span class="hljs-function">end</span></span><br><span class="line"><span class="hljs-function">----------</span></span><br><span class="line"><span class="hljs-function">[CSharpCallLua]</span></span><br><span class="line"><span class="hljs-function"><span class="hljs-keyword">private</span> <span class="hljs-keyword">delegate</span> <span class="hljs-keyword">void</span> <span class="hljs-title">Action0</span>(<span class="hljs-params"></span>)</span>;</span><br><span class="line"></span><br><span class="line">Action0 action0 = luaenv.Global.Get&lt;Action0&gt;(<span class="hljs-string">"action0"</span>);</span><br><span class="line">action0();</span><br></pre></td></tr></table></figure>

<p><strong>返回lua函数指针:</strong></p>
<figure class="highlight csharp hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="hljs-function">function <span class="hljs-title">action0</span>(<span class="hljs-params"></span>)</span></span><br><span class="line"><span class="hljs-function">	<span class="hljs-title">print</span>(<span class="hljs-params"><span class="hljs-string">"action0 call "</span></span>)</span></span><br><span class="line"><span class="hljs-function">end</span></span><br><span class="line"><span class="hljs-function"></span></span><br><span class="line"><span class="hljs-function">function <span class="hljs-title">getaction</span>(<span class="hljs-params"></span>)</span></span><br><span class="line"><span class="hljs-function">	return action0</span>;</span><br><span class="line">end</span><br></pre></td></tr></table></figure>

<figure class="highlight csharp hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">[<span class="hljs-meta">CSharpCallLua</span>]</span><br><span class="line"><span class="hljs-function"><span class="hljs-keyword">private</span> <span class="hljs-keyword">delegate</span> <span class="hljs-keyword">void</span> <span class="hljs-title">Action0</span>(<span class="hljs-params"></span>)</span>;</span><br><span class="line">[<span class="hljs-meta">CSharpCallLua</span>]</span><br><span class="line"><span class="hljs-function"><span class="hljs-keyword">private</span> <span class="hljs-keyword">delegate</span> Action0 <span class="hljs-title">GetAction</span>(<span class="hljs-params"></span>)</span>;</span><br><span class="line">	</span><br><span class="line">GetAction getaction = luaenv.Global.Get&lt;GetAction&gt;(<span class="hljs-string">"getaction"</span>);</span><br><span class="line">(getaction())();</span><br></pre></td></tr></table></figure>

<h4 id="7-LuaFunction映射全局函数"><a href="#7-LuaFunction映射全局函数" class="headerlink" title="7.LuaFunction映射全局函数"></a>7.LuaFunction映射全局函数</h4><p>用该类访问Lua函数会有boxing，unboxing的开销。为了性能考虑，需要频繁调用的地方不要用该类。建议通过table.Get<foodelegate>获取一个delegate调用。</foodelegate></p>
<figure class="highlight csharp hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">LuaFunction lf = luaenv.Global.Get&lt;LuaFunction&gt;(<span class="hljs-string">"action0"</span>);</span><br><span class="line">lf.Call();</span><br></pre></td></tr></table></figure>

<p><strong><em>代价比较大，推荐使用单独的模块负责管理其加载，而不是每次用之前去加载</em></strong></p>
<hr>
<h3 id="GetInPath"><a href="#GetInPath" class="headerlink" title="GetInPath"></a>GetInPath</h3><p>T GetInPath<t>(string path)<br>和Get的区别是，这个函数会识别path里的.。</t></p>
<p>比如var i = tbl.GetInPath<int>(“a.b.c”)相当于在lua里执行i = tbl.a.b.c，避免仅为了获取中间变量而多次调用Get，执行效率更高。</int></p>
<hr>
<h3 id="SetInPath"><a href="#SetInPath" class="headerlink" title="SetInPath"></a>SetInPath</h3><p>void SetInPath<t>(string path, T val)</t></p>
<p>和GetInPath对应的setter</p>
<hr>
<h2 id="xLua调用C"><a href="#xLua调用C" class="headerlink" title="xLua调用C#"></a>xLua调用C#</h2><hr>
<h3 id="访问C-静态方法、静态属性"><a href="#访问C-静态方法、静态属性" class="headerlink" title="访问C#静态方法、静态属性"></a>访问C#静态方法、静态属性</h3><figure class="highlight lua hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="hljs-keyword">local</span> go1 = CS.UnityEngine.GameObject(<span class="hljs-string">"Cube"</span>);</span><br><span class="line"></span><br><span class="line"><span class="hljs-keyword">local</span> Time = CS.UnityEngine.Time;</span><br><span class="line"><span class="hljs-built_in">print</span>(<span class="hljs-string">"Time.deltaTime:"</span>,Time.deltaTime);	</span><br><span class="line"></span><br><span class="line"><span class="hljs-keyword">local</span> GameObject = CS.UnityEngine.GameObject;</span><br><span class="line"><span class="hljs-keyword">local</span> mainCamera = GameObject.Find(<span class="hljs-string">"Main Camera"</span>);</span><br></pre></td></tr></table></figure>

<h3 id="typeof函数"><a href="#typeof函数" class="headerlink" title="typeof函数"></a>typeof函数</h3><figure class="highlight lua hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">newGameObj:AddComponent(typeof(CS.UnityEngine.ParticleSystem))</span><br></pre></td></tr></table></figure>

<h3 id="访问自定义的C-类"><a href="#访问自定义的C-类" class="headerlink" title="访问自定义的C#类"></a>访问自定义的C#类</h3><p>如果要通过Lua访问自己定义的类的话，需要给被Lua代码访问的类加上一个[LuaCallCSharp]，用来生成Lua的适配代码.<br>xLua只会生成加了该配置的类型，不会自动生成其父类的适配代码，当访问子类对象的父类方法，如果该父类加了LuaCallCSharp配置，则执行父类的适配代码，否则会尝试用反射来访问<br>反射访问除了性能不佳之外，在il2cpp下还有可能因为代码剪裁而导致无法访问，后者可以通过下面介绍的ReflectionUse标签来避免。</p>
<figure class="highlight csharp hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">[<span class="hljs-meta">LuaCallCSharp</span>]</span><br><span class="line"><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title">BaseClass</span></span><br><span class="line">&#123;</span><br><span class="line">    <span class="hljs-keyword">public</span> <span class="hljs-keyword">string</span> BaseField = <span class="hljs-string">"baseField"</span>;</span><br><span class="line">	<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">BasePrint</span>(<span class="hljs-params"></span>)</span></span><br><span class="line"><span class="hljs-function"></span>    &#123;</span><br><span class="line">        Debug.Log(<span class="hljs-string">"BasePrint"</span>);</span><br><span class="line"></span><br><span class="line">    &#125;</span><br><span class="line">	</span><br><span class="line">	<span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">string</span> BaseStatic = <span class="hljs-string">"BaseStatic"</span>;</span><br><span class="line">	<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">BaseStaticPrint</span>(<span class="hljs-params"></span>)</span></span><br><span class="line"><span class="hljs-function"></span>    &#123;</span><br><span class="line">        Debug.Log(<span class="hljs-string">"BaseStaticPrint"</span>);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>//lua</p>
<figure class="highlight lua hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="hljs-keyword">local</span> baseClass = CS.BaseClass();</span><br><span class="line"><span class="hljs-built_in">print</span>(<span class="hljs-string">"baseClass:"</span>,baseClass.BaseField)</span><br><span class="line">baseClass:BasePrint();</span><br><span class="line">//静态变量和函数</span><br><span class="line"><span class="hljs-keyword">local</span> BaseClass = CS.BaseClass;</span><br><span class="line"><span class="hljs-built_in">print</span>(<span class="hljs-string">"basestatic:"</span>,BaseClass.BaseStatic)</span><br><span class="line">BaseClass.BaseStaticPrint();</span><br></pre></td></tr></table></figure>

<h3 id="可变参数和默认参数"><a href="#可变参数和默认参数" class="headerlink" title="可变参数和默认参数"></a>可变参数和默认参数</h3><figure class="highlight csharp hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line">[<span class="hljs-meta">LuaCallCSharp</span>]</span><br><span class="line"><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title">BaseClass</span></span><br><span class="line">&#123;</span><br><span class="line">    <span class="hljs-keyword">public</span> <span class="hljs-keyword">string</span> BaseField = <span class="hljs-string">"baseField"</span>;</span><br><span class="line">    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">Ping</span>(<span class="hljs-params"><span class="hljs-keyword">int</span> arg0,<span class="hljs-keyword">string</span> arg1</span>)</span></span><br><span class="line"><span class="hljs-function"></span>    &#123;</span><br><span class="line">        Debug.Log(<span class="hljs-string">"=========C#========="</span>);</span><br><span class="line">        Debug.Log(<span class="hljs-string">"arg0:"</span> + arg0);</span><br><span class="line">        Debug.Log(<span class="hljs-string">"arg1:"</span> + arg1);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">Ping</span>(<span class="hljs-params"><span class="hljs-keyword">int</span> arg0,<span class="hljs-keyword">params</span> <span class="hljs-keyword">string</span>[] args</span>)</span></span><br><span class="line"><span class="hljs-function"></span>    &#123;</span><br><span class="line">        Debug.Log(<span class="hljs-string">"arg0:"</span> + arg0);</span><br><span class="line">        Debug.Log(<span class="hljs-string">"args:"</span>);</span><br><span class="line">        <span class="hljs-keyword">foreach</span> (<span class="hljs-keyword">string</span> arg <span class="hljs-keyword">in</span> args)</span><br><span class="line">        &#123;</span><br><span class="line">            Debug.Log(arg + <span class="hljs-string">" "</span>);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<figure class="highlight lua hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">//lua</span><br><span class="line"> baseClass:Ping(<span class="hljs-number">0</span>,<span class="hljs-string">"22222"</span>,<span class="hljs-string">"3333"</span>,<span class="hljs-string">"444"</span>,<span class="hljs-string">"555"</span>);</span><br></pre></td></tr></table></figure>

<h3 id="访问枚举"><a href="#访问枚举" class="headerlink" title="访问枚举"></a>访问枚举</h3><figure class="highlight csharp hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line">[<span class="hljs-meta">LuaCallCSharp</span>]</span><br><span class="line"><span class="hljs-keyword">public</span> <span class="hljs-keyword">enum</span> Language</span><br><span class="line">&#123;</span><br><span class="line">    CN,</span><br><span class="line">    ZH</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">[<span class="hljs-meta">LuaCallCSharp</span>]</span><br><span class="line"><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title">BaseClass</span></span><br><span class="line">&#123;</span><br><span class="line">    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">Ping</span>(<span class="hljs-params">Language lan</span>)</span></span><br><span class="line"><span class="hljs-function"></span>    &#123;</span><br><span class="line">        <span class="hljs-keyword">switch</span> (lan)</span><br><span class="line">        &#123;</span><br><span class="line">            <span class="hljs-keyword">case</span> Language.CN:</span><br><span class="line">                &#123;</span><br><span class="line">                    Debug.Log(<span class="hljs-string">"CN"</span>);</span><br><span class="line">                    <span class="hljs-keyword">break</span>;</span><br><span class="line">                &#125;</span><br><span class="line">            <span class="hljs-keyword">case</span> Language.ZH:</span><br><span class="line">                &#123;</span><br><span class="line">                    Debug.Log(<span class="hljs-string">"ZH"</span>);</span><br><span class="line">                    <span class="hljs-keyword">break</span>;</span><br><span class="line">                &#125;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>//lua</p>
<figure class="highlight lua hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="hljs-keyword">local</span> Language = CS.Language;</span><br><span class="line"><span class="hljs-keyword">local</span> baseClass = CS.BaseClass();</span><br><span class="line"></span><br><span class="line">baseClass:Ping(Language.CN)</span><br><span class="line">baseClass:Ping(Language.ZH)</span><br></pre></td></tr></table></figure>

<h3 id="访问C-委托"><a href="#访问C-委托" class="headerlink" title="访问C#委托"></a>访问C#委托</h3><figure class="highlight csharp hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">[<span class="hljs-meta">LuaCallCSharp</span>]</span><br><span class="line"><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title">BaseClass</span></span><br><span class="line">&#123;</span><br><span class="line">    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">delegate</span> <span class="hljs-keyword">void</span> <span class="hljs-title">ActionString</span>(<span class="hljs-params"><span class="hljs-keyword">string</span> arg</span>)</span>;</span><br><span class="line">    <span class="hljs-keyword">public</span> ActionString Ping = (<span class="hljs-keyword">string</span> lan) =&gt;</span><br><span class="line">    &#123;</span><br><span class="line">        Debug.Log(<span class="hljs-string">"Action:"</span> + lan);</span><br><span class="line">    &#125;;</span><br><span class="line">    </span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>//lua</p>
<figure class="highlight lua hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="hljs-keyword">local</span> baseClass = CS.BaseClass();</span><br><span class="line"><span class="hljs-keyword">local</span> action = baseClass.Ping;//委托函数</span><br><span class="line"><span class="hljs-keyword">local</span> actionstring = CS.BaseClass.ActionString;//委托声明</span><br><span class="line">//定义一个lua函数</span><br><span class="line"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">lua_action</span><span class="hljs-params">(arg)</span></span></span><br><span class="line">	<span class="hljs-built_in">print</span>(<span class="hljs-string">"lua_action:"</span>,<span class="hljs-built_in">arg</span>)</span><br><span class="line"><span class="hljs-keyword">end</span></span><br><span class="line">//声明lua_action</span><br><span class="line">actionstring = lua_action</span><br><span class="line">actionstring(<span class="hljs-string">"hello0"</span>); //必须执行一次，委托函数才能 +</span><br><span class="line"></span><br><span class="line">action(<span class="hljs-string">"hello1"</span>);//必须执行一次，委托函数才能 +</span><br><span class="line">action = action + actionstring</span><br><span class="line">action(<span class="hljs-string">"hello3"</span>);//此时才会调用<span class="hljs-number">2</span>个函数。</span><br><span class="line">action = action - actionstring</span><br></pre></td></tr></table></figure>

<h3 id="类型转换"><a href="#类型转换" class="headerlink" title="类型转换"></a>类型转换</h3><p><strong>cast</strong> ：类型转换</p>
<figure class="highlight lua hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="hljs-keyword">local</span> whorehouse = CS.WhoreHouse()</span><br><span class="line"><span class="hljs-keyword">local</span> woman = whorehouse:GetWhore()</span><br><span class="line">woman:Fuck()</span><br><span class="line">cast(woman, typeof(CS.IFuckable))</span><br><span class="line">woman:Fuck()</span><br></pre></td></tr></table></figure>


        </div>
        
        <div class="level is-size-7 is-uppercase">
            <div class="level-start">
                <div class="level-item">
                    <span class="is-size-6 has-text-grey has-mr-7">#</span>
                    <a class="has-link-grey -link" href="/mystudy/tags/学习/">学习</a>
                </div>
            </div>
        </div>
        
        

        
        <div class="social-share"></div>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/social-share.js@1.0.16/dist/css/share.min.css">
<script src="https://cdn.jsdelivr.net/npm/social-share.js@1.0.16/dist/js/social-share.min.js"></script>
        
    </div>
</div>





<div class="card card-transparent">
    <div class="level post-navigation is-flex-wrap is-mobile">
        
        <div class="level-start">
            <a class="level level-item has-link-grey  article-nav-prev" href="/mystudy/2019/08/28/3D数学基础-图形与游戏开发-2/">
                <i class="level-item fas fa-chevron-left"></i>
                <span class="level-item">3D数学基础:图形与游戏开发-矩阵</span>
            </a>
        </div>
        
        
        <div class="level-end">
            <a class="level level-item has-link-grey  article-nav-next" href="/mystudy/2019/08/19/shade学习-1/">
                <span class="level-item">shader学习1-顶点/片元着色器的基本结构</span>
                <i class="level-item fas fa-chevron-right"></i>
            </a>
        </div>
        
    </div>
</div>


</div>
                




<div class="column is-4-tablet is-4-desktop is-3-widescreen  has-order-1 column-left ">
    
        
<div class="card widget">
    <div class="card-content">
        <nav class="level">
            <div class="level-item has-text-centered" style="flex-shrink: 1">
                <div>
                    
                        <img class="image is-128x128 has-mb-6" src="/mystudy/images/avatar2.jpg" alt="满头大汉老黄牛">
                    
                    
                    <p class="is-size-4 is-block">
                        满头大汉老黄牛
                    </p>
                    
                    
                    <p class="is-size-6 is-block">
                        游戏
                    </p>
                    
                    
                    <p class="is-size-6 is-flex is-flex-center has-text-grey">
                        <i class="fas fa-map-marker-alt has-mr-7"></i>
                        <span>火星</span>
                    </p>
                    
                </div>
            </div>
        </nav>
        <nav class="level is-mobile">
            <div class="level-item has-text-centered is-marginless">
                <div>
                    <p class="heading">
                        文章
                    </p>
                    <p class="title has-text-weight-normal">
                        70
                    </p>
                </div>
            </div>
            <div class="level-item has-text-centered is-marginless">
                <div>
                    <p class="heading">
                        分类
                    </p>
                    <p class="title has-text-weight-normal">
                        10
                    </p>
                </div>
            </div>
            <div class="level-item has-text-centered is-marginless">
                <div>
                    <p class="heading">
                        标签
                    </p>
                    <p class="title has-text-weight-normal">
                        3
                    </p>
                </div>
            </div>
        </nav>
        <div class="level">
            <a class="level-item button is-link is-rounded" href="https://github.com/koliy/" target="_blank">
                关注我</a>
        </div>
        
        
        <div class="level is-mobile">
            
            <a class="level-item button is-white is-marginless" target="_blank"
                title="Github" href="https://github.com/koliy/">
                
                <i class="fab fa-github"></i>
                
            </a>
            
        </div>
        
    </div>
</div>
    
        


    
        
<div class="card widget">
    <div class="card-content">
        <div class="menu">
            <h3 class="menu-label">
                分类
            </h3>
            <ul class="menu-list">
            <li>
        <a class="level is-marginless" href="/mystudy/categories/3D数学基础-图形与游戏开发/">
            <span class="level-start">
                <span class="level-item">3D数学基础:图形与游戏开发</span>
            </span>
            <span class="level-end">
                <span class="level-item tag">3</span>
            </span>
        </a></li><li>
        <a class="level is-marginless" href="/mystudy/categories/AI/">
            <span class="level-start">
                <span class="level-item">AI</span>
            </span>
            <span class="level-end">
                <span class="level-item tag">12</span>
            </span>
        </a></li><li>
        <a class="level is-marginless" href="/mystudy/categories/MySql/">
            <span class="level-start">
                <span class="level-item">MySql</span>
            </span>
            <span class="level-end">
                <span class="level-item tag">1</span>
            </span>
        </a></li><li>
        <a class="level is-marginless" href="/mystudy/categories/SurfaceShader/">
            <span class="level-start">
                <span class="level-item">SurfaceShader</span>
            </span>
            <span class="level-end">
                <span class="level-item tag">1</span>
            </span>
        </a></li><li>
        <a class="level is-marginless" href="/mystudy/categories/Unity/">
            <span class="level-start">
                <span class="level-item">Unity</span>
            </span>
            <span class="level-end">
                <span class="level-item tag">1</span>
            </span>
        </a></li><li>
        <a class="level is-marginless" href="/mystudy/categories/git/">
            <span class="level-start">
                <span class="level-item">git</span>
            </span>
            <span class="level-end">
                <span class="level-item tag">3</span>
            </span>
        </a></li><li>
        <a class="level is-marginless" href="/mystudy/categories/shade学习/">
            <span class="level-start">
                <span class="level-item">shade学习</span>
            </span>
            <span class="level-end">
                <span class="level-item tag">33</span>
            </span>
        </a></li><li>
        <a class="level is-marginless" href="/mystudy/categories/xlua/">
            <span class="level-start">
                <span class="level-item">xlua</span>
            </span>
            <span class="level-end">
                <span class="level-item tag">1</span>
            </span>
        </a></li><li>
        <a class="level is-marginless" href="/mystudy/categories/网络同步/">
            <span class="level-start">
                <span class="level-item">网络同步</span>
            </span>
            <span class="level-end">
                <span class="level-item tag">10</span>
            </span>
        </a></li><li>
        <a class="level is-marginless" href="/mystudy/categories/设计模式/">
            <span class="level-start">
                <span class="level-item">设计模式</span>
            </span>
            <span class="level-end">
                <span class="level-item tag">5</span>
            </span>
        </a></li>
            </ul>
        </div>
    </div>
</div>
    
        <div class="card widget">
    <div class="card-content">
        <div class="menu">
        <h3 class="menu-label">
            归档
        </h3>
        <ul class="menu-list">
        
        <li>
            <a class="level is-marginless" href="/mystudy/archives/2020/09/">
                <span class="level-start">
                    <span class="level-item">九月 2020</span>
                </span>
                <span class="level-end">
                    <span class="level-item tag">1</span>
                </span>
            </a>
        </li>
        
        <li>
            <a class="level is-marginless" href="/mystudy/archives/2020/07/">
                <span class="level-start">
                    <span class="level-item">七月 2020</span>
                </span>
                <span class="level-end">
                    <span class="level-item tag">23</span>
                </span>
            </a>
        </li>
        
        <li>
            <a class="level is-marginless" href="/mystudy/archives/2020/06/">
                <span class="level-start">
                    <span class="level-item">六月 2020</span>
                </span>
                <span class="level-end">
                    <span class="level-item tag">17</span>
                </span>
            </a>
        </li>
        
        <li>
            <a class="level is-marginless" href="/mystudy/archives/2020/03/">
                <span class="level-start">
                    <span class="level-item">三月 2020</span>
                </span>
                <span class="level-end">
                    <span class="level-item tag">2</span>
                </span>
            </a>
        </li>
        
        <li>
            <a class="level is-marginless" href="/mystudy/archives/2020/02/">
                <span class="level-start">
                    <span class="level-item">二月 2020</span>
                </span>
                <span class="level-end">
                    <span class="level-item tag">4</span>
                </span>
            </a>
        </li>
        
        <li>
            <a class="level is-marginless" href="/mystudy/archives/2019/09/">
                <span class="level-start">
                    <span class="level-item">九月 2019</span>
                </span>
                <span class="level-end">
                    <span class="level-item tag">5</span>
                </span>
            </a>
        </li>
        
        <li>
            <a class="level is-marginless" href="/mystudy/archives/2019/08/">
                <span class="level-start">
                    <span class="level-item">八月 2019</span>
                </span>
                <span class="level-end">
                    <span class="level-item tag">18</span>
                </span>
            </a>
        </li>
        
        </ul>
        </div>
    </div>
</div>
    
        
<div class="card widget">
    <div class="card-content">
        <h3 class="menu-label">
            标签云
        </h3>
        <a href="/mystudy/tags/game/" style="font-size: 15px;">game</a> <a href="/mystudy/tags/git/" style="font-size: 10px;">git</a> <a href="/mystudy/tags/学习/" style="font-size: 20px;">学习</a>
    </div>
</div>

    
    
        <div class="column-right-shadow is-hidden-widescreen is-sticky">
        
            
<div class="card widget" id="toc">
    <div class="card-content">
        <div class="menu">
            <h3 class="menu-label">
                目录
            </h3>
            <ul class="menu-list"><li>
        <a class="is-flex" href="#LuaEnv类">
        <span class="has-mr-6">1</span>
        <span>LuaEnv类</span>
        </a><ul class="menu-list"><li>
        <a class="is-flex" href="#Tick">
        <span class="has-mr-6">1.1</span>
        <span>Tick</span>
        </a></li><li>
        <a class="is-flex" href="#Dispose">
        <span class="has-mr-6">1.2</span>
        <span>Dispose</span>
        </a></li><li>
        <a class="is-flex" href="#Global">
        <span class="has-mr-6">1.3</span>
        <span>Global</span>
        </a></li><li>
        <a class="is-flex" href="#DoString">
        <span class="has-mr-6">1.4</span>
        <span>DoString</span>
        </a></li><li>
        <a class="is-flex" href="#加载lua文件">
        <span class="has-mr-6">1.5</span>
        <span>加载lua文件</span>
        </a></li><li>
        <a class="is-flex" href="#AddLoader">
        <span class="has-mr-6">1.6</span>
        <span>AddLoader</span>
        </a></li></ul></li><li>
        <a class="is-flex" href="#LuaTable类">
        <span class="has-mr-6">2</span>
        <span>LuaTable类</span>
        </a><ul class="menu-list"><li>
        <a class="is-flex" href="#Get">
        <span class="has-mr-6">2.1</span>
        <span>Get</span>
        </a><ul class="menu-list"><li>
        <a class="is-flex" href="#获取一个table表">
        <span class="has-mr-6">2.1.1</span>
        <span>获取一个table表</span>
        </a></li><li>
        <a class="is-flex" href="#1-以class做映射">
        <span class="has-mr-6">2.1.2</span>
        <span>1.以class做映射:</span>
        </a></li><li>
        <a class="is-flex" href="#2-Dictionary做映射">
        <span class="has-mr-6">2.1.3</span>
        <span>2.Dictionary做映射</span>
        </a></li><li>
        <a class="is-flex" href="#3-以LuaTable映射">
        <span class="has-mr-6">2.1.4</span>
        <span>3.以LuaTable映射</span>
        </a></li><li>
        <a class="is-flex" href="#4-以List做映射">
        <span class="has-mr-6">2.1.5</span>
        <span>4.以List做映射</span>
        </a></li><li>
        <a class="is-flex" href="#5-以interface做映射">
        <span class="has-mr-6">2.1.6</span>
        <span>5.以interface做映射</span>
        </a></li><li>
        <a class="is-flex" href="#6-获取全局函数">
        <span class="has-mr-6">2.1.7</span>
        <span>6. 获取全局函数</span>
        </a></li><li>
        <a class="is-flex" href="#7-LuaFunction映射全局函数">
        <span class="has-mr-6">2.1.8</span>
        <span>7.LuaFunction映射全局函数</span>
        </a></li></ul></li><li>
        <a class="is-flex" href="#GetInPath">
        <span class="has-mr-6">2.2</span>
        <span>GetInPath</span>
        </a></li><li>
        <a class="is-flex" href="#SetInPath">
        <span class="has-mr-6">2.3</span>
        <span>SetInPath</span>
        </a></li></ul></li><li>
        <a class="is-flex" href="#xLua调用C">
        <span class="has-mr-6">3</span>
        <span>xLua调用C#</span>
        </a><ul class="menu-list"><li>
        <a class="is-flex" href="#访问C-静态方法、静态属性">
        <span class="has-mr-6">3.1</span>
        <span>访问C#静态方法、静态属性</span>
        </a></li><li>
        <a class="is-flex" href="#typeof函数">
        <span class="has-mr-6">3.2</span>
        <span>typeof函数</span>
        </a></li><li>
        <a class="is-flex" href="#访问自定义的C-类">
        <span class="has-mr-6">3.3</span>
        <span>访问自定义的C#类</span>
        </a></li><li>
        <a class="is-flex" href="#可变参数和默认参数">
        <span class="has-mr-6">3.4</span>
        <span>可变参数和默认参数</span>
        </a></li><li>
        <a class="is-flex" href="#访问枚举">
        <span class="has-mr-6">3.5</span>
        <span>访问枚举</span>
        </a></li><li>
        <a class="is-flex" href="#访问C-委托">
        <span class="has-mr-6">3.6</span>
        <span>访问C#委托</span>
        </a></li><li>
        <a class="is-flex" href="#类型转换">
        <span class="has-mr-6">3.7</span>
        <span>类型转换</span>
        </a></li></ul></li></ul>
        </div>
    </div>
</div>

        
        </div>
    
</div>

                




<div class="column is-4-tablet is-4-desktop is-3-widescreen is-hidden-touch is-hidden-desktop-only has-order-3 column-right is-sticky">
    
        
<div class="card widget" id="toc">
    <div class="card-content">
        <div class="menu">
            <h3 class="menu-label">
                目录
            </h3>
            <ul class="menu-list"><li>
        <a class="is-flex" href="#LuaEnv类">
        <span class="has-mr-6">1</span>
        <span>LuaEnv类</span>
        </a><ul class="menu-list"><li>
        <a class="is-flex" href="#Tick">
        <span class="has-mr-6">1.1</span>
        <span>Tick</span>
        </a></li><li>
        <a class="is-flex" href="#Dispose">
        <span class="has-mr-6">1.2</span>
        <span>Dispose</span>
        </a></li><li>
        <a class="is-flex" href="#Global">
        <span class="has-mr-6">1.3</span>
        <span>Global</span>
        </a></li><li>
        <a class="is-flex" href="#DoString">
        <span class="has-mr-6">1.4</span>
        <span>DoString</span>
        </a></li><li>
        <a class="is-flex" href="#加载lua文件">
        <span class="has-mr-6">1.5</span>
        <span>加载lua文件</span>
        </a></li><li>
        <a class="is-flex" href="#AddLoader">
        <span class="has-mr-6">1.6</span>
        <span>AddLoader</span>
        </a></li></ul></li><li>
        <a class="is-flex" href="#LuaTable类">
        <span class="has-mr-6">2</span>
        <span>LuaTable类</span>
        </a><ul class="menu-list"><li>
        <a class="is-flex" href="#Get">
        <span class="has-mr-6">2.1</span>
        <span>Get</span>
        </a><ul class="menu-list"><li>
        <a class="is-flex" href="#获取一个table表">
        <span class="has-mr-6">2.1.1</span>
        <span>获取一个table表</span>
        </a></li><li>
        <a class="is-flex" href="#1-以class做映射">
        <span class="has-mr-6">2.1.2</span>
        <span>1.以class做映射:</span>
        </a></li><li>
        <a class="is-flex" href="#2-Dictionary做映射">
        <span class="has-mr-6">2.1.3</span>
        <span>2.Dictionary做映射</span>
        </a></li><li>
        <a class="is-flex" href="#3-以LuaTable映射">
        <span class="has-mr-6">2.1.4</span>
        <span>3.以LuaTable映射</span>
        </a></li><li>
        <a class="is-flex" href="#4-以List做映射">
        <span class="has-mr-6">2.1.5</span>
        <span>4.以List做映射</span>
        </a></li><li>
        <a class="is-flex" href="#5-以interface做映射">
        <span class="has-mr-6">2.1.6</span>
        <span>5.以interface做映射</span>
        </a></li><li>
        <a class="is-flex" href="#6-获取全局函数">
        <span class="has-mr-6">2.1.7</span>
        <span>6. 获取全局函数</span>
        </a></li><li>
        <a class="is-flex" href="#7-LuaFunction映射全局函数">
        <span class="has-mr-6">2.1.8</span>
        <span>7.LuaFunction映射全局函数</span>
        </a></li></ul></li><li>
        <a class="is-flex" href="#GetInPath">
        <span class="has-mr-6">2.2</span>
        <span>GetInPath</span>
        </a></li><li>
        <a class="is-flex" href="#SetInPath">
        <span class="has-mr-6">2.3</span>
        <span>SetInPath</span>
        </a></li></ul></li><li>
        <a class="is-flex" href="#xLua调用C">
        <span class="has-mr-6">3</span>
        <span>xLua调用C#</span>
        </a><ul class="menu-list"><li>
        <a class="is-flex" href="#访问C-静态方法、静态属性">
        <span class="has-mr-6">3.1</span>
        <span>访问C#静态方法、静态属性</span>
        </a></li><li>
        <a class="is-flex" href="#typeof函数">
        <span class="has-mr-6">3.2</span>
        <span>typeof函数</span>
        </a></li><li>
        <a class="is-flex" href="#访问自定义的C-类">
        <span class="has-mr-6">3.3</span>
        <span>访问自定义的C#类</span>
        </a></li><li>
        <a class="is-flex" href="#可变参数和默认参数">
        <span class="has-mr-6">3.4</span>
        <span>可变参数和默认参数</span>
        </a></li><li>
        <a class="is-flex" href="#访问枚举">
        <span class="has-mr-6">3.5</span>
        <span>访问枚举</span>
        </a></li><li>
        <a class="is-flex" href="#访问C-委托">
        <span class="has-mr-6">3.6</span>
        <span>访问C#委托</span>
        </a></li><li>
        <a class="is-flex" href="#类型转换">
        <span class="has-mr-6">3.7</span>
        <span>类型转换</span>
        </a></li></ul></li></ul>
        </div>
    </div>
</div>

    
    
</div>

            </div>
        </div>
    </section>
    <footer class="footer">
    <div class="container1">
        <div class="level1">
            <div class="level-start1 has-text-centered-mobile1">
                <a class="footer-logo is-block has-mb-6" href="/mystudy/">
                

                
                </a>
                <p class="is-size-7">
                &copy; 2020 Koliy&nbsp;
                Powered by <a href="https://github.com/koliy/koliy.github.io" target="_blank">Hexo</a> & <a
                        href="https://github.com/ppoffice/hexo-theme-icarus" target="_blank">Icarus</a>
                
                <br>
                <span id="busuanzi_container_site_uv">
                共<span id="busuanzi_value_site_uv">0</span>个访客
                </span>
                
                </p>
            </div>
            <div class="level-end1">
            
            </div>
        </div>
    </div>
</footer>
    <script src="https://cdn.jsdelivr.net/npm/jquery@3.3.1/dist/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/moment@2.22.2/min/moment-with-locales.min.js"></script>
<script>moment.locale("zh-CN");</script>

<script>
var IcarusThemeSettings = {
    article: {
        highlight: {
            clipboard: true,
            fold: 'unfolded'
        }
    }
};
</script>


    <script src="https://cdn.jsdelivr.net/npm/clipboard@2.0.4/dist/clipboard.min.js" defer></script>



    
    
    
    <script src="/mystudy/js/animation.js"></script>
    

    
    
    
    <script src="https://cdn.jsdelivr.net/npm/lightgallery@1.6.8/dist/js/lightgallery.min.js" defer></script>
    <script src="https://cdn.jsdelivr.net/npm/justifiedGallery@3.7.0/dist/js/jquery.justifiedGallery.min.js" defer></script>
    <script src="/mystudy/js/gallery.js" defer></script>
    

    
    

<div id="outdated">
    <h6>Your browser is out-of-date!</h6>
    <p>Update your browser to view this website correctly. <a id="btnUpdateBrowser" href="http://outdatedbrowser.com/">Update
            my browser now </a></p>
    <p class="last"><a href="#" id="btnCloseUpdateBrowser" title="Close">&times;</a></p>
</div>
<script src="https://cdn.jsdelivr.net/npm/outdatedbrowser@1.1.5/outdatedbrowser/outdatedbrowser.min.js" defer></script>
<script>
    document.addEventListener("DOMContentLoaded", function () {
        outdatedBrowser({
            bgColor: '#f25648',
            color: '#ffffff',
            lowerThan: 'flex'
        });
    });
</script>


    
    
<script src="https://cdn.jsdelivr.net/npm/mathjax@2.7.5/unpacked/MathJax.js?config=TeX-MML-AM_CHTML" defer></script>
<script>
document.addEventListener('DOMContentLoaded', function () {
    MathJax.Hub.Config({
        'HTML-CSS': {
            matchFontHeight: false
        },
        SVG: {
            matchFontHeight: false
        },
        CommonHTML: {
            matchFontHeight: false
        },
        tex2jax: {
            inlineMath: [
                ['$','$'],
                ['\\(','\\)']
            ]
        }
    });
});
</script>

    
    

<a id="back-to-top" title="回到顶端" href="javascript:;">
    <i class="fas fa-chevron-up"></i>
</a>
<script src="/mystudy/js/back-to-top.js" defer></script>


    
    

    
    
    
    

    
    
    
    
    

    


<script src="/mystudy/js/main.js" defer></script>

    
    <div class="searchbox ins-search">
    <div class="searchbox-container ins-search-container">
        <div class="searchbox-input-wrapper">
            <input type="text" class="searchbox-input ins-search-input" placeholder="想要查找什么..." />
            <span class="searchbox-close ins-close ins-selectable"><i class="fa fa-times-circle"></i></span>
        </div>
        <div class="searchbox-result-wrapper ins-section-wrapper">
            <div class="ins-section-container"></div>
        </div>
    </div>
</div>
<script>
    (function (window) {
        var INSIGHT_CONFIG = {
            TRANSLATION: {
                POSTS: '文章',
                PAGES: '页面',
                CATEGORIES: '分类',
                TAGS: '标签',
                UNTITLED: '(无标题)',
            },
            CONTENT_URL: '/mystudy/content.json',
        };
        window.INSIGHT_CONFIG = INSIGHT_CONFIG;
    })(window);
</script>
<script src="/mystudy/js/insight.js" defer></script>
<link rel="stylesheet" href="/mystudy/css/search.css">
<link rel="stylesheet" href="/mystudy/css/insight.css"><!-- hexo-inject:begin --><!-- Begin: Injected MathJax -->
<script type="text/x-mathjax-config">
  MathJax.Hub.Config({"tex2jax":{"inlineMath":[["$","$"],["\\(","\\)"]],"skipTags":["script","noscript","style","textarea","pre","code"],"processEscapes":true},"TeX":{"equationNumbers":{"autoNumber":"AMS"}}});
</script>

<script type="text/x-mathjax-config">
  MathJax.Hub.Queue(function() {
    var all = MathJax.Hub.getAllJax(), i;
    for(i=0; i < all.length; i += 1) {
      all[i].SourceElement().parentNode.className += ' has-jax';
    }
  });
</script>

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js">
</script>
<!-- End: Injected MathJax -->
<!-- hexo-inject:end -->
    
</body>
</html>